﻿<UserControl x:Class="Soat.HappyNet.Silverlight.Modules.SalesOrder.Views.ShoppingCartView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:windowControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"             
    xmlns:regions="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:controls="clr-namespace:Soat.HappyNet.Silverlight.Library.Controls;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
    xmlns:behavior="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:action="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Actions;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:trigger="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Triggers;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:helper="clr-namespace:Soat.HappyNet.Silverlight.Library.Helpers;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
    <Grid x:Name="LayoutRoot">
        <controls:AnimatedExpander x:Name="ShoppingCartExpander"
                                   Style="{StaticResource NiceAnimatedExpanderStyle}"
                                   Header="{Binding Path=Strings.SALES_ShoppingCart, Source={StaticResource LocalizedStrings}}"
                                   HorizontalContentAlignment="Stretch">
            <Grid MinHeight="50"
                  Margin="0,5,0,0">
                <Grid>
                    <i:Interaction.Behaviors>
                        <behavior:BoolValueVisibilityBehavior
                            ValueBinding="{Binding ShoppingCartItems.Count, Converter={StaticResource IsPositiveConverter}}" />
                    </i:Interaction.Behaviors>
                    
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <data:DataGrid x:Name="ShoppingCartDataGrid" IsReadOnly="True"
                                   Style="{StaticResource DataGridStyle}"
                                   Grid.Row="0"
                                   AutoGenerateColumns="False"
                                   ItemsSource="{Binding ShoppingCartItems}"
                                   HorizontalContentAlignment="Stretch"
                                   BorderThickness="0">
                        <data:DataGrid.Columns>
                            <data:DataGridTemplateColumn Header="Produit" MaxWidth="140">
                                <data:DataGridTemplateColumn.HeaderStyle>
                                    <Style TargetType="dataprimitives:DataGridColumnHeader" BasedOn="{StaticResource DataGridColumnHeaderStyle}">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Strings.SALES_Product, Source={StaticResource LocalizedStrings}}"/>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </data:DataGridTemplateColumn.HeaderStyle>
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Grid Margin="2,1">
                                            <TextBlock Text="{Binding Product.Name}"
                                                       TextWrapping="Wrap"
                                                       Style="{StaticResource LabelStyle}"/>
                                        </Grid>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>
                            <data:DataGridTemplateColumn Header="Quantité" CanUserResize="False">
                                <data:DataGridTemplateColumn.HeaderStyle>
                                    <Style TargetType="dataprimitives:DataGridColumnHeader" BasedOn="{StaticResource DataGridColumnHeaderStyle}">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Strings.SALES_Quantity, Source={StaticResource LocalizedStrings}}"/>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </data:DataGridTemplateColumn.HeaderStyle>
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Grid VerticalAlignment="Center"
                                              Margin="2,1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>

                                            <TextBox Text="{Binding Quantity, Mode=TwoWay}"
                                                     Grid.Column="0"/>
                                            
                                            <Button Style="{StaticResource ButtonNoStyle}"
                                                    cal:Click.Command="{Binding Tag.RemoveCartItemCommand, RelativeSource={RelativeSource Self}}"
                                                    cal:Click.CommandParameter="{Binding}"
                                                    Grid.Column="1">
                                                <helper:BindingHelper.Binding>
                                                    <helper:BindingProperties SourceProperty="DataContext" 
                                                                              RelativeSourceAncestorType="DataGrid"
                                                                              TargetProperty="Tag"/>
                                                </helper:BindingHelper.Binding>
                                                <ToolTipService.ToolTip>
                                                    <ToolTip Style="{StaticResource ToolTipStyle}"
                                                             Content="{Binding Strings.SALES_RemoveCartItem, Source={StaticResource LocalizedStrings}}" />
                                                </ToolTipService.ToolTip>
                                                <Image Source="../../Assets/Images/cancel.png" 
                                                       Stretch="Uniform"
                                                       MaxHeight="20"/>
                                            </Button>

                                        </Grid>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>
                            <data:DataGridTemplateColumn Header="Prix">
                                <data:DataGridTemplateColumn.HeaderStyle>
                                    <Style TargetType="dataprimitives:DataGridColumnHeader" BasedOn="{StaticResource DataGridColumnHeaderStyle}">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Strings.SALES_Cost, Source={StaticResource LocalizedStrings}}"/>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </data:DataGridTemplateColumn.HeaderStyle>
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <toolkit:WrapPanel VerticalAlignment="Center"
                                                    Orientation="Horizontal"
                                                    Margin="2,1">
                                            <TextBlock Text="{Binding Product.Price, 
                                                                      Converter={StaticResource FormatConverter}, 
                                                                      ConverterParameter='{0:0.00}'}"
                                                       Margin="0,0,5,0"/>
                                            <TextBlock Text="{Binding Product.Currency}" />
                                        </toolkit:WrapPanel>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>
                        </data:DataGrid.Columns>
                    </data:DataGrid>

                    <Button Content="{Binding Strings.SALES_Checkout, Source={StaticResource LocalizedStrings}}"
                            Grid.Row="1"
                            HorizontalAlignment="Right"
                            Padding="18,4"
                            Margin="4,6"
                            cal:Click.Command="{Binding CheckoutCommand}"
                            Style="{StaticResource ButtonStyle}">
                        <Button.Background>
                            <SolidColorBrush Color="{StaticResource TitleHeaderColor}"  />
                        </Button.Background>
                    </Button>
                </Grid>

                <TextBlock Style="{StaticResource BoldLabelStyle}" 
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text="{Binding Strings.SALES_EmptyCart, Source={StaticResource LocalizedStrings}}">
                    <i:Interaction.Behaviors>
                        <behavior:BoolValueVisibilityBehavior
                            Negate="True"
                            ValueBinding="{Binding ShoppingCartItems.Count, Converter={StaticResource IsPositiveConverter}}" />
                    </i:Interaction.Behaviors>
                </TextBlock>

            </Grid>
        </controls:AnimatedExpander>
    </Grid>
</UserControl>
